﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ServiceMReviewer.Repositories;
using ServiceMReviewer.DTO;

namespace ServiceMReviewer
{
    /// <summary>
    /// Handler multiple request in WCF
    /// </summary>
    [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)]
    public class SvcMReviewer : ISvcMReviewer
    {
        /////////////////// ESTABLISHMENTTYPE ///////////////////
        public List<EstablishmentTypeDTO> EstablishmentType_SelectAll()
        {
            var lstDto = new List<EstablishmentTypeDTO>();
            var rpt = new EstablishmentTypeRepository();
            var lstEntity = rpt.SelectAll();
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentTypeDTO.Translate(item));
            return lstDto;
        }
        public EstablishmentTypeDTO EstablishmentType_SelectByID(int id)
        {
            var rpt = new EstablishmentTypeRepository();
            return EstablishmentTypeDTO.Translate(rpt.SelectByID(id));
        }
        public bool EstablishmentType_Insert(EstablishmentTypeDTO obj)
        {
            var rpt = new EstablishmentTypeRepository();
            var entity = EstablishmentTypeDTO.Reverse(obj);
            return rpt.Insert(entity);
        }
        public bool EstablishmentType_Delete(int id)
        {
            var rpt = new EstablishmentTypeRepository();
            return rpt.Delete(id);
        }
        public bool EstablishmentType_Update(EstablishmentTypeDTO obj)
        {
            var rpt = new EstablishmentTypeRepository();
            var entity = rpt.SelectByID(obj.ID);
            obj.UpdateEntity(ref entity);
            return rpt.Save();
        }
        public List<EstablishmentTypeDTO> EstablishmentType_RetrieveByID(int id)
        {
            var rpt = new EstablishmentTypeRepository();
            var lstDto = new List<EstablishmentTypeDTO>();
            var lstEntity = rpt.RetrieveByID(id);
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentTypeDTO.Translate(item));
            return lstDto;
        }
        /////////////////// ESTABLISHMENT ///////////////////
        public List<EstablishmentDTO> Establishment_SelectAll()
        {
            var lstDto = new List<EstablishmentDTO>();
            var rpt = new EstablishmentRepository();
            var lstEntity = rpt.SelectAll();
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentDTO.Translate(item));
            return lstDto;
        }
        public EstablishmentDTO Establishment_SelectByID(string id)
        {
            var rpt = new EstablishmentRepository();
            return EstablishmentDTO.Translate(rpt.SelectByID(id));
        }
        public bool Establishment_Insert(EstablishmentDTO obj)
        {
            var rpt = new EstablishmentRepository();
            var entity = EstablishmentDTO.Reverse(obj);
            return rpt.Insert(entity);
        }
        public bool Establishment_Delete(string id)
        {
            var rpt = new EstablishmentRepository();
            return rpt.Delete(id);
        }
        public bool Establishment_Update(EstablishmentDTO obj)
        {
            var rpt = new EstablishmentRepository();
            var entity = rpt.SelectByID(obj.ID);
            obj.UpdateEntity(ref entity);
            return rpt.Save();
        }
        public List<EstablishmentDTO> Establishment_RetrieveByID(string id)
        {
            var rpt = new EstablishmentRepository();
            var lstDto = new List<EstablishmentDTO>();
            var lstEntity = rpt.RetrieveByID(id);
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentDTO.Translate(item));
            return lstDto;
        }
        public List<EstablishmentDTO> Establishment_SelectByEstablishmentType(int establishmenttype)
        {
            var rpt = new EstablishmentRepository();
            var lstDto = new List<EstablishmentDTO>();
            var lstEntity = rpt.SelectByIDEstablishmentType(establishmenttype);
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentDTO.Translate(item));
            return lstDto;
        }
        public List<EstablishmentDTO> Establishment_SelectByFoodType(int foodtype)
        {
            var rpt = new EstablishmentRepository();
            var lstDto = new List<EstablishmentDTO>();
            var lstEntity = rpt.SelectByIDFoodType(foodtype);
            foreach (var item in lstEntity)
                lstDto.Add(EstablishmentDTO.Translate(item));
            return lstDto;
        }
        /////////////////// MEALTYPE ///////////////////
        public List<MealTypeDTO> MealType_SelectAll()
        {
            var lstDto = new List<MealTypeDTO>();
            var rpt = new MealTypeRepository();
            var lstEntity = rpt.SelectAll();
            foreach (var item in lstEntity)
                lstDto.Add(MealTypeDTO.Translate(item));
            return lstDto;
        }
        public MealTypeDTO MealType_SelectByID(int id)
        {
            var rpt = new MealTypeRepository();
            return MealTypeDTO.Translate(rpt.SelectByID(id));
        }
        public bool MealType_Insert(MealTypeDTO obj)
        {
            var rpt = new MealTypeRepository();
            var entity = MealTypeDTO.Reverse(obj);
            return rpt.Insert(entity);
        }
        public bool MealType_Delete(int id)
        {
            var rpt = new MealTypeRepository();
            return rpt.Delete(id);
        }
        public bool MealType_Update(MealTypeDTO obj)
        {
            var rpt = new MealTypeRepository();
            var entity = rpt.SelectByID(obj.ID);
            obj.UpdateEntity(ref entity);
            return rpt.Save();
        }
        public List<MealTypeDTO> MealType_RetrieveByID(int id)
        {
            var rpt = new MealTypeRepository();
            var lstDto = new List<MealTypeDTO>();
            var lstEntity = rpt.RetrieveByID(id);
            foreach (var item in lstEntity)
                lstDto.Add(MealTypeDTO.Translate(item));
            return lstDto;
        }
        /////////////////// REVIEW ///////////////////
        public List<ReviewDTO> Review_SelectAll()
        {
            var lstDto = new List<ReviewDTO>();
            var rpt = new ReviewRepository();
            var lstEntity = rpt.SelectAll();
            foreach (var item in lstEntity)
                lstDto.Add(ReviewDTO.Translate(item));
            return lstDto;
        }
        public ReviewDTO Review_SelectByID(int id)
        {
            var rpt = new ReviewRepository();
            return ReviewDTO.Translate(rpt.SelectByID(id));
        }
        public bool Review_Insert(ReviewDTO obj)
        {
            var rpt = new ReviewRepository();
            var entity = ReviewDTO.Reverse(obj);
            return rpt.Insert(entity);
        }
        public bool Review_Delete(int id)
        {
            var rpt = new ReviewRepository();
            return rpt.Delete(id);
        }
        public bool Review_Update(ReviewDTO obj)
        {
            var rpt = new ReviewRepository();
            var entity = rpt.SelectByID(obj.ID);
            obj.UpdateEntity(ref entity);
            return rpt.Save();
        }
        public List<ReviewDTO> Review_RetrieveByID(int id)
        {
            var rpt = new ReviewRepository();
            var lstDto = new List<ReviewDTO>();
            var lstEntity = rpt.RetrieveByID(id);
            foreach (var item in lstEntity)
                lstDto.Add(ReviewDTO.Translate(item));
            return lstDto;
        }
        public List<ReviewDTO> Review_SelectByEstablisment(string establisment)
        {
            var rpt = new ReviewRepository();
            var lstDto = new List<ReviewDTO>();
            var lstEntity = rpt.SelectByIDEstablisment(establisment);
            foreach (var item in lstEntity)
                lstDto.Add(ReviewDTO.Translate(item));
            return lstDto;
        }
        public List<ReviewDTO> Review_SelectByMealType(int mealtype)
        {
            var rpt = new ReviewRepository();
            var lstDto = new List<ReviewDTO>();
            var lstEntity = rpt.SelectByIDMealType(mealtype);
            foreach (var item in lstEntity)
                lstDto.Add(ReviewDTO.Translate(item));
            return lstDto;
        }
        /////////////////// FOODTYPE ///////////////////
        public List<FoodTypeDTO> FoodType_SelectAll()
        {
            var lstDto = new List<FoodTypeDTO>();
            var rpt = new FoodTypeRepository();
            var lstEntity = rpt.SelectAll();
            foreach (var item in lstEntity)
                lstDto.Add(FoodTypeDTO.Translate(item));
            return lstDto;
        }
        public FoodTypeDTO FoodType_SelectByID(int id)
        {
            var rpt = new FoodTypeRepository();
            return FoodTypeDTO.Translate(rpt.SelectByID(id));
        }
        public bool FoodType_Insert(FoodTypeDTO obj)
        {
            var rpt = new FoodTypeRepository();
            var entity = FoodTypeDTO.Reverse(obj);
            return rpt.Insert(entity);
        }
        public bool FoodType_Delete(int id)
        {
            var rpt = new FoodTypeRepository();
            return rpt.Delete(id);
        }
        public bool FoodType_Update(FoodTypeDTO obj)
        {
            var rpt = new FoodTypeRepository();
            var entity = rpt.SelectByID(obj.ID);
            obj.UpdateEntity(ref entity);
            return rpt.Save();
        }
        public List<FoodTypeDTO> FoodType_RetrieveByID(int id)
        {
            var rpt = new FoodTypeRepository();
            var lstDto = new List<FoodTypeDTO>();
            var lstEntity = rpt.RetrieveByID(id);
            foreach (var item in lstEntity)
                lstDto.Add(FoodTypeDTO.Translate(item));
            return lstDto;
        }
    }
}
